<!--
 * @Author: Karl Liris
 * @Date: 2021-02-23 15:09:05
 * @LastEditTime: 2021-02-26 10:51:32
-->
<template>
  <div class="login">
    <div class="form-item">
      <label for="iUserName">用户名：</label>
      <input type="text" name="username" id="iUserName" v-model="username">
    </div>
    <div class="form-item">
      <label for="iPassword">密码：</label>
      <input type="password" name="password" id="iPassword" v-model="password">
    </div>
    <div class="form-item">
      <button type="button" @click="login">登录</button>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'App',
  data() {
    return {
      username: '18602690564',
      password: '690564',
    };
  },
  mounted() {
    this.$electron.ipcRenderer.on('login', (event, data) => {
      if (data.success) {
        this.$router.push('/login');
      } else {
        alert(data.msg);
      }
    });
  },
  methods: {
    login() {
      // this.$electron.ipcRenderer.send('login', {
      //   username: this.username,
      //   password: this.password,
      // });
      axios.post('https://bi.tcsl.com.cn/bi_proxy/api/auth/login/bi', {
        username: this.username,
        password: this.password,
      }).then(({ data }) => {
        if (data.success) {
          this.$router.push('/');
        } else {
          alert(data.msg);
        }
      });
    },
  },
}
</script>
